/*
 * services.cpp
 *
 *  Created on: 2014-1-14
 *      Author: iot
 */
#include "services.h"
#include "util.h"

__namespace_bjp_start__

int Services::UserLogin(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;

	string procpath = "./VMSService";
	string output = util::get_proc_stdout(procpath, iargs);

	//Parse output from XML format to vector<string>.
	ptree pt;
	stringstream ss;
	ss << output;
	read_xml(ss, pt);
//	try
//	{
//		string UserName = pt.get<string>("UserName");
//		string UserLevel = pt.get<string>("UserLevel");
//		string ClientSessionID = pt.get<string>("ClientSessionID");
//		oargs.push_back(UserName);
//		oargs.push_back(UserLevel);
//		oargs.push_back(ClientSessionID);
//	}
//	catch (...)
//	{//Some error occurred, see logs in vmslog directory.
//		retval = pt.get<int>("message");
//	}

	return (retval);
}

int Services::UserLogoff(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;

	string procpath = "./VMSService";
	string output = util::get_proc_stdout(procpath, iargs);

	//Parse output from XML format to vector<string>.
	ptree pt;
	stringstream ss;
	ss << output;
	read_xml(ss, pt);
	try
	{
		retval = pt.get<int>("message");
	}
	catch (...)
	{//Some error occurred, see logs in vmslog directory.
		retval = -1;
	}

	return (retval);
}

int Services::GetPassword(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;

	string procpath = "./VMSService";
	string output = util::get_proc_stdout(procpath, iargs);

	//Parse output from XML format to vector<string>.
	ptree pt;
	stringstream ss;
	ss << output;
	read_xml(ss, pt);
	try
	{
		string PassWord = pt.get<string>("PassWord");
		oargs.push_back(PassWord);
	}
	catch (...)
	{//Some error occurred, see logs in vmslog directory.
		retval = pt.get<int>("message");
	}

	return (retval);
}

int Services::ControlPTZ(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;
	string procpath = "./OnvifController";
	oargs.push_back(util::get_proc_stdout(procpath, iargs));
	for(int i = 0;i<iargs.size();i++)
		printf("%s\n", iargs[i].c_str());
	return retval;
}

int Services::SetDecoderConf(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;
	string procpath = "./OnvifController";
	oargs.push_back(util::get_proc_stdout(procpath, iargs));
	for(int i = 0;i<iargs.size();i++)
		printf("%s\n", iargs[i].c_str());
	return retval;
}

int Services::GetOnvifInfo(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;
	string procpath = "./VMSService";
	oargs.push_back(util::get_proc_stdout(procpath, iargs));
	return retval;
}

int Services::GetResourceList(vector<string> &iargs, vector<string> &oargs)
{
	int retval = 0;
	string procpath = "./VMSService";
	oargs.push_back(util::get_proc_stdout(procpath, iargs));
	return retval;
}
__namespace_bjp_end__










